﻿<% @ Language=VBScript %>
<% Option Explicit %>

<!--#include file="includes/hash1way.asp" -->
<!--#include file="includes/database.asp" -->
<!--#include file="includes/global_varaiable.asp" -->


<!--#include file="header.asp"-->

<script language="javascript" src="customer_add_ajax.js" type="text/javascript"></script>

<script>
function CheckfrmReg() {
	var blnValid = true;
	var msg = 'Bạn chưa nhập đầy đủ thông tin hoặc thông tin sai, vui lòng kiểm tra những mục dưới đây:';
	if (document.frmReg.cardnumber.value=="") {
		blnValid = false;
		msg  += '\n- Mã số thẻ';
	}
	
	if(document.frmReg.cardnumber.value.indexOf("'") != -1)	{
			blnValid = false;
		msg  += '\n- Mã số thẻ';
		}

	if (document.frmReg.password.value=="") {
		blnValid = false;
		msg  += '\n- Password';
	}

	if (document.frmReg.fullname.value=="") {
		blnValid = false;
		msg  += '\n- Họ tên';
	}

	if (document.frmReg.email.value=="") {
		blnValid = false;
		msg  += '\n- Email';
	}
	if (document.frmReg.phone.value=="") {
		blnValid = false;
		msg  += '\n- Số điện thoại';
	}
	
	if (document.frmReg.address.value=="") {
		blnValid = false;
		msg  += '\n- Địa chỉ';
	}
	if (!blnValid) alert (msg);

	// Bat dau kiem tra email
	if (document.frmReg.email.value == "") {
		alert("Vui lòng nhập địa chỉ email!");
		document.frmReg.email.focus();
		return false;
	}
	else
	{ 
		var e_check  = document.frmReg.email.value;
		if(document.frmReg.email.value.indexOf(" ") != -1)	{
			alert("Email không hợp lệ!");
			document.frmReg.email.focus(); 
			return false;
		}
		if(document.frmReg.email.value.indexOf("@") == -1)	{
			alert("Email không hợp lệ!");
			document.frmReg.email.focus(); 
			return false;
		}
	   	validarr = document.frmReg.email.value.split("@");   
	   	if(validarr[1].length==0){
		   	alert("Email không hợp lệ!");
		   	document.frmReg.email.focus(); 
		   	return false;
	   	}
	   	if(validarr[1].length != 0){ 
			if(validarr[1].indexOf(".") == -1){
				alert("Email không hợp lệ!");
				document.frmReg.email.focus(); 
				return false;
			}
			validemail = validarr[1].split(".");
			if(validemail[1].length==0) {
				alert("Email không hợp lệ!");
				document.frmReg.email.focus(); 
				return false;
			}
		}   
	}
	
	return blnValid;
}
</script>


</head>

<body>

<%

	If (CurrentUserLevel() < 1) then
		Response.Write(vbCrLf & "<script language=""JavaScript"">")
		Response.Write(vbCrLf & "window.location = 'login.asp'")
		Response.Write(vbCrLf & "</script>")
	End If

'Không cho nhập ký tự đặc biệt gây lỗi
function fixL(s)
			s = replace(s,"'","")
	s= replace(s,"#'","")
	fixL = replace(s,";'","")
	end function

Dim cardnumber
Dim password
Dim email
Dim fullname
Dim phone
Dim id
Dim gender 
Dim dob_d2
Dim dob_m2
Dim dob_y4
Dim birthday
Dim address
Dim ip
Dim status

cardnumber = Trim(Mid(Request.Form("cardnumber"), 1, 20))
password = LCase(Trim(Mid(Request.Form("password"), 1, 15)))

password = HashEncode(password)
email = Request.Form("email")
fullname = Request.Form("fullname")
phone = Request.Form("phone")
id = Request.Form("id")
gender = Request.Form("gender")
dob_d2 = Request.Form("dob_d2")
dob_m2 = Request.Form("dob_m2")
dob_y4 = Request.Form("dob_y4")
birthday = dob_m2 & "/" & dob_d2 & "/" & dob_y4
address = Request.Form("address")
ip = Request.ServerVariables("REMOTE_ADDR")

If gender = 0 then
	gender = 0
Else
	gender = 1
End if

status=0
if(Request.Form("status")="1") then
 status=1
end if

If Request("act") = "save" then

  	
strSQL = "INSERT INTO KHACHHANG (CardNumber, Password, Email, FullName, Gender, Address, Birthdate, Phone, ID, Creator, DateCreated, IP, Status) "&_ 
		"VALUES ('" & cardnumber & "', '" & password & "', '" & email & "', '" & fullname & "', " & gender & ", '" & address & "', '" & birthday & "', '" & phone & "', '" & id & "', '" & Session("StaffID") & "', '" & now() & "', '" & ip & "', " & status & ")"

adoCon.Execute(strSQL)

'response.write(strSQL)

Session("Message") = "Thêm thành công"
	
End If


%>
<p><span class="aspmaker">Add to TABLE: KHACHHANG<br><br><a href="staff_list.asp">Back to List</a></span></p>
<form method=post name="frmReg" onsubmit="return CheckfrmReg();" action="customer_add.asp?act=save">

<%
If Session("Message") <> "" Then
%>
<p><span class="ewmsg"><%= Session("Message") %></span></p>
<%
	Session("Message") = "" ' Clear message
End If
%>

<p>
<table class="ewTable">
	
	<tr id="r_Username">
		<td class="ewTableHeader"><span>Số thẻ</span></td>
		<td class="ewTableAltRow"><span>
		<input name="cardnumber" type="text" size="30" onkeyup="showHint(this.value)" autocomplete="off">* <span id="txtHint"></span>
		</span></td>
	</tr>
	
	<tr id="r_Password">
		<td class="ewTableHeader"><span>Password</span></td>
		<td class="ewTableAltRow"><span>
		<input name="password" type="text" size="30">*
		</span></td>
	</tr>
	
	<tr id="r_FullName">
		<td class="ewTableHeader"><span>Họ tên</span></td>
		<td class="ewTableAltRow"><span>
		<input name="fullname" type="text" size="30">*
		</span></td>
	</tr>
	
	<tr id="r_Email">
		<td class="ewTableHeader"><span>Email</span></td>
		<td class="ewTableAltRow"><span>
		<input name="email" type="text" size="30">*
		</span></td>
	</tr>
	
	<tr id="r_Phone">
		<td class="ewTableHeader"><span>Điện thoại</span></td>
		<td class="ewTableAltRow"><span>
		<input name="phone" type="text" size="30">*
		</span></td>
	</tr>
	
	<tr id="r_CMND">
		<td class="ewTableHeader"><span>Số CMND</span></td>
		<td class="ewTableAltRow"><span>
		<input name="id" type="text" size="30">*
		</span></td>
	</tr>
	
	<tr id="r_CMND">
		<td class="ewTableHeader"><span>Giới tính</span></td>
		<td class="ewTableAltRow"><span>
		<input type="radio" name="gender" value=0 checked>Nữ&nbsp;
		<input type="radio" name="gender" value=1>Nam
		</span></td>
	</tr>
	
	<tr id="r_Birthday">
		<td class="ewTableHeader"><span>Sinh nhật</span></td>
		<td class="ewTableAltRow"><span>
		<select class="textform" id="dob_d2" style="WIDTH: 60px" name="dob_d2">
		<%
		dim it
						
			for it=1 to 31 
				dim it1
				if it < 10 then
					it1= "0" & it
				else
					it1= it
				end if
					Response.Write("<option value='" & it & "'>" & it1 & "</option>")
				next 
		%>
		</select>
		<select class="textform" id="dob_m2" style="WIDTH: 100px" name="dob_m2">
		<%
			for it=1 to 12
				Response.Write("<option value='" & it & "'>Tháng " & it & "</option>")
			next 
						
		%>
		</select> 
					
		<input class="textform" id="dob_y4" alt="rq_full" style="WIDTH: 35px" maxlength="4" size="4" name="dob_y4">*
		</span></td>
	</tr>
	
	<tr id="r_Address">
		<td class="ewTableHeader"><span>Địa chỉ</span></td>
		<td class="ewTableAltRow"><span>
		<input name="address" type="text" size="30">*
		</span></td>
	</tr>
	
	<tr id="r_Active">
		<td class="ewTableHeader"><span>Kích hoạt</span></td>
		<td class="ewTableAltRow"><span>
		<input name="status" id="status" value="1" type="checkbox" />
		</span></td>
	</tr>
	
</table>
<p><span class="ewmsg">Những ô có dấu * là thông tin bắt buộc</span></p>
<p>
<input name="submit" type="submit" value="Thêm khách hàng">
</form>


<!--#include file="footer.asp"-->